/*
	Copyright (C) 2009 jungil Han <jungil.Han@gmail.com>

	This program is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#include "mkURLDialog.h"
#include <QLineEdit>

mkURLDialog::mkURLDialog( IN QWidget *a_pParent, IN Qt::WindowFlags a_eFlags ) : mkDialog( a_pParent, a_eFlags )
{
	m_pLineEdit = NULL;
	m_pConfirmButton = NULL;
}

mkURLDialog::~mkURLDialog()
{
	MK_DELETE( m_pLineEdit );
	MK_DELETE( m_pConfirmButton );
}

void mkURLDialog::OnInitDialog()
{
	/* Set the dialog's title */
	setWindowTitle( QString( "Open URL" ));

	/* Set the dialog's size */
	resize( 200, 35 );
	setMaximumSize( 200, 35 );
	setMinimumSize( 200, 35 );

	m_pLineEdit = new QLineEdit( this );
	m_pLineEdit->setGeometry( 5, 5, 145, 25 );

	if ( !m_pConfirmButton ) {
		m_pConfirmButton = new mkButton( this );
		m_pConfirmButton->SetBGImage( QString( ":/URL/url_confirm_btn_bg_default.png" ), QString( ":/URL/url_confirm_btn_bg_over.png" ), QString( ":/URL/url_confirm_btn_bg_click.png" ));
		m_pConfirmButton->setGeometry( 155, 5, 40, 25 );
		QRect fontRect( 0, 0, 40, 25 );
		m_pConfirmButton->SetText( QString( "OK" ), &fontRect, 7, Qt::AlignCenter );
		connect( m_pConfirmButton, SIGNAL( clicked() ), this, SLOT( accept() ));
	}
}

void mkURLDialog::showEvent( QShowEvent *a_pEvent )
{
	m_pLineEdit->setFocus();

	QPoint point;
	point.setX( parentWidget()->x() + parentWidget()->width() - width() );
	point.setY( parentWidget()->y() - height() );
	move( point );
}

int mkURLDialog::Show( IN const QString &a_refCurrentUrl)
{
	if ( !a_refCurrentUrl.isEmpty() ) {
		m_pLineEdit->setText( a_refCurrentUrl );
		m_pLineEdit->selectAll ();
	} else {
		m_pLineEdit->clear();
	}

	return exec();
}

QString mkURLDialog::GetText()
{
	return m_pLineEdit->text();
}
